<?php
$idparcours=$_GET["idparcours"];
//$idparcours=0;


$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="db431888431"; // Database name 

$dbLink = mysql_connect($host, $username, $password);

if (!$dbLink) die("Impossible d'établir une connexion sur la base de données: " . mysql_error());
$dbSelected = mysql_select_db($db_name, $dbLink);
if (!$dbSelected) die ('We\'re connected, but can\'t use the table: ' . mysql_error());
?>
<form method="post" action="envoyerCarte.php">
<table width="80%" border="1" align="right">
<thead>
<tr>
	<?php
		$today = date("d.m.y");  
	echo "<th><input style =\"text-align:center\" type=\"text\" readonly=\"true\" name=\"date\" size=\"9\" value=\"" . $today . "\"></th>";
	$query 		= 'SELECT id, name FROM courses where id =' . $idparcours;
	$result 	= mysql_query($query);
	if(mysql_num_rows($result) ){
		while($row = mysql_fetch_array($result))  {
			$parcoursName = $row['name'];
		}	
	}
	echo "<th colspan=\"20\">
	<input style =\"text-align:center\" type=\"text\" readonly=\"true\" name=\"parcoursname\" size=\"60\" value=\"" . $parcoursName . "\"></th>\n";
	
	echo "<input style =\"text-align:center\" type=\"hidden\" readonly=\"true\" name=\"parcoursid\" size=\"6\" value=\"" . $idparcours . "\"></th>\n";
?>

</tr>
</thead>
<tr>
<td>Trou</td>
<?php
$query 		= 'SELECT num, par FROM courses_hole WHERE id_course = ' . $idparcours . ' order by num';
$result 	= mysql_query($query);
if(mysql_num_rows($result) ){
	while($row = mysql_fetch_array($result))  {
		echo "<td>". $row['num'] . "</td>";
	}	
}
else {
	echo "aucun parcours trouvé.";
}
?>
</tr>
<tr>
<td>Par</td>
<?php
$query 		= 'SELECT num, par FROM courses_hole WHERE id_course = "' . $idparcours . '" order by num';
$result 	= mysql_query($query);
if(mysql_num_rows($result) ){
	while($row = mysql_fetch_array($result))  {
		echo "<td><input style =\"text-align:center\" type=\"text\" readonly=\"true\" name=\"PAR" . $row['num'] ."\" size=\"1\" value=\"" . $row['par'] . "\"></td>\n";
		//echo "<td>" . $row['par'] . "</td>\n";
	
	}	
}
else {
	echo "aucun parcours trouvé.";
}
	
?>
</tr>
<tr>
<td>Brut</td>
<?php
$query 		= 'SELECT num, par FROM courses_hole WHERE id_course = "' . $idparcours . '" order by num';
$result 	= mysql_query($query);
if(mysql_num_rows($result) ){
	while($row = mysql_fetch_array($result))  {
	//	echo "<td><input style =\"text-align:center\" type=\"text\" name=\"S" . $row['num'] ."\" size=\"1\" placeholder=\"" . $row['par'] . "\"></td>\n";
		echo "<td><input style =\"text-align:center\" type=\"text\" name=\"S[]\" size=\"1\" placeholder=\"" . $row['par'] . "\"></td>\n";

	}	
}
else {
	echo "aucun parcours trouvé.";
}?>
</tr>
<tr>
<td>A/P</td>
<?php
$query 		= 'SELECT num, par FROM courses_hole WHERE id_course = "' . $idparcours . '" order by num';
$result 	= mysql_query($query);
if(mysql_num_rows($result) ){
	while($row = mysql_fetch_array($result))  {
		//echo "<td><input style =\"text-align:center\" type=\"checkbox\"  name=\"AP" . $row['num'] ."\" size=\"1\"></td>\n";
		echo "<td><input style =\"text-align:center\" type=\"checkbox\"  name=\"AP[]\" size=\"1\" value =\"" . $row['num'] . "\"></td>\n";

	}	
}
else {
	echo "aucun parcours trouvé.";
}?>
</tr>
<tr>
<td>Putts</td>
<?php
$query 		= 'SELECT num, par FROM courses_hole WHERE id_course = "' . $idparcours . '" order by num';
$result 	= mysql_query($query);
if(mysql_num_rows($result) ){
	while($row = mysql_fetch_array($result))  {
		//echo "<td><input style =\"text-align:center\" type=\"text\" name=\"P" . $row['num'] ."\" size=\"1\" placeholder=\"" . $row['par'] . "\"></td>\n";
		echo "<td><input style =\"text-align:center\" type=\"text\" name=\"P[]\" size=\"1\" placeholder=\"" . $row['par'] . "\"></td>\n";

	}	
}
else {
	echo "aucun parcours trouvé.";
}?>

</tr>
<tfoot>
<tr>
<td colspan="23"><input type="submit" name="register" value="Enregistrer" class="button"></td>
</tr>
</tfoot>
</table>
</form>
<?php
?>